package top.xunfong.file.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {
    @Bean("deleteFileTaskExecutor")
    public ExecutorService deleteFileTaskExecutor() {
        return new ThreadPoolExecutor(
                2, // 核心线程数
                10, // 最大线程数
                60L, // 存活时间， 60秒
                TimeUnit.SECONDS, // 单位
                new LinkedBlockingDeque<>(100), // 任务队列
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略, 超出时，谁提交谁执行
        );
    }
}
